package com.jugheadzhou.emrpoc.controller;

import com.alibaba.fastjson.JSON;
import com.jugheadzhou.emrpoc.common.Result;
import com.jugheadzhou.emrpoc.dto.MedicalRecordDto;
import com.jugheadzhou.emrpoc.service.MedicalRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author jugheadzhou
 * @date 2021-10-24
 */
@Slf4j
@RestController
@RequestMapping("/mr")
public class MedicalRecordController {

    @Resource
    private MedicalRecordService medicalRecordService;

    /**
     * 病历查询
     *
     * @param medicalRecordDto 查询参数
     * @return
     */
    @GetMapping("list")
    public Result<?> list(MedicalRecordDto medicalRecordDto) {
        return Result.success(medicalRecordService.list(medicalRecordDto));
    }

    /**
     * 病历保存
     *
     * @param medicalRecordDto 保存的病历对象
     * @return
     */
    @PostMapping("save")
    public Result<?> save(@Valid @RequestBody MedicalRecordDto medicalRecordDto) {
        log.info("病历保存开始：{}", JSON.toJSONString(medicalRecordDto));
        return Result.success(medicalRecordService.save(medicalRecordDto));
    }

}
